package com.kgc.chapter01.vars

object Test_Five {
  def main(args: Array[String]): Unit = {
    val nums = List(1, 2, 3, 4, 5, 6, 7, 8)
    println(filter(nums, modN(2))) // ? def mod(x: Int) = ((x % 2) == 0)
    println(filter(nums, modN(3)))

  }

  def filter(xs: List[Int], p: Int => Boolean): List[Int] =
    if (xs.isEmpty) xs
    else if (p(xs.head)) xs.head :: filter(xs.tail, p)
    else filter(xs.tail, p)

  def modN(n: Int)(x: Int) = ((x % n) == 0)

}
